package com.jiangyg.mall.db.druid;

import com.alibaba.druid.pool.DruidDataSourceStatLoggerAdapter;
import com.alibaba.druid.pool.DruidDataSourceStatValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 类描述：数据库状态日志记录
 * 
 * @author jiangyg
 * @date 2019-10-20
 * @version 2.0
 */
public class DBStatLogger extends DruidDataSourceStatLoggerAdapter {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(DBStatLogger.class);

    public DBStatLogger() {

    }

    @Override
    public void log(DruidDataSourceStatValue statValue) {
        if (logger.isInfoEnabled()) {
            int activeCount = statValue.getActiveCount();
            long closeCount = statValue.getCloseCount();
            long commitCount = statValue.getCommitCount();
            long connectCount = statValue.getConnectCount();
            long errorCount = statValue.getErrorCount();
            long executeCount = statValue.getExecuteCount();
            int initialSize = statValue.getInitialSize();
            int maxActive = statValue.getMaxActive();
            int minIdle = statValue.getMinIdle();
            long rollbackCount = statValue.getRollbackCount();
            logger.info("数据库[" + statValue.getName() + "]当前状态：[activeCount=" + activeCount + ",closeCount=" + closeCount + ",commitCount=" + commitCount + ",connectCount=" + connectCount + ",errorCount=" + errorCount + ",executeCount=" + executeCount + ",initialSize=" + initialSize + ",maxActive=" + maxActive + ",minIdle=" + minIdle + ",rollbackCount=" + rollbackCount + "]");
        }
    }

}
